package com.gopay.common.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * 属性工具类,读取属性文件
 * @author wangdong
 */
public class PropertiesUtil {

    private static ResourceBundle rb;

    private static BufferedInputStream inputStream;


    /**
     * 根据key从web.properties文件中获取value值
     *
     * @param key
     * @return
     */
    public static String getRedisValue(String key) {
        URL resource = PropertiesUtil.class.getClassLoader().getResource("redis.properties");
        if (resource!=null){
            String filePath = resource.getFile();
            try {
                inputStream = new BufferedInputStream(new FileInputStream(filePath));
                rb = new PropertyResourceBundle(inputStream);
                return rb.getString(key);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            
        }
        return "";
    }
}
